#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @File  : python_1.py
# @Author: Zhang
# @Date  : 2017/11/17
# @Desc  :

# 案列名：判断是否为子串

str_a='欢迎'
str_b='欢迎乔锐花同学'

# if str_a in  str_b:
#
#     print('是子串')
# else:
#     print('不是子串')

# 定义函数

def is_sub_str(sub_strs,strs):
    """ 判断sub_strs是否为strs 的子串
    :param sub_strs: 子串
    :param strs: 父串
    :return:
    """
    if sub_strs in strs:
        return True
    else:
        return False

a = is_sub_str(str_a,str_b)
print(a)

#判断一个串是否为另一个通过循环移位产生的串

#循环移位

def right_move(strs,n_steps):
    """

    :param strs: 待移动的子串
    :param n_steps: 移动的步数
    :return:
    """
    length = len(strs)
    if length == 0:
        return strs
    steps = n_steps%length
    ret_strs = strs[-n_steps:]+strs[:-n_steps]
    return ret_strs

a =right_move(str_b,3)
print(a)

def can_rotate_get_substrs(strs,sub_str):
    """
    判断sub_str是否为strs循环右移动的子串
    :param strs:父串
    :param sub_str:子串
    :return:
    """
    # a= [i for i in range(10)]
    # print(a)
    length = len(strs)
    for i in range(length):
        if is_sub_str(sub_str,right_move(strs,1)):
            return True
    return False


fla = can_rotate_get_substrs(str_b,str_a)
print(fla)

